using System;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace Nevoweb.Modules.NB_Store.CategoryFilter
{
    public partial class Settings : ModuleSettingsBase
    {


        #region Base Method Implementations

        public override void LoadSettings()
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    txtTemplateText.Text = Localization.GetString("DefaultTemplate", LocalResourceFile);

                    if (ModuleSettings["chkCasCade"] != null) chkCasCade.Checked = Convert.ToBoolean(ModuleSettings["chkCasCade"]);
                    if (ModuleSettings["txtTabId"] != null) txtTabId.Text = ModuleSettings["txtTabId"].ToString();
                    if (ModuleSettings["txtDepth"] != null) txtDepth.Text = ModuleSettings["txtDepth"].ToString();
                    if (ModuleSettings["txtTemplateText"] != null && ModuleSettings["txtTemplateText"].ToString() != "") txtTemplateText.Text = ModuleSettings["txtTemplateText"].ToString();
                    if (ModuleSettings["chkAndMode"] != null) chkAndMode.Checked = Convert.ToBoolean(ModuleSettings["chkAndMode"]);

                }
                //Module failed to load
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        public override void UpdateSettings()
        {
            try
            {
                // update replace token setting
                var objModules = new ModuleController();
                objModules.UpdateModuleSetting(ModuleId, "chkCasCade", chkCasCade.Checked.ToString());
                objModules.UpdateModuleSetting(ModuleId, "txtTabId", txtTabId.Text);
                objModules.UpdateModuleSetting(ModuleId, "txtDepth", txtDepth.Text);
                objModules.UpdateModuleSetting(ModuleId, "txtTemplateText", txtTemplateText.Text);
                objModules.UpdateModuleSetting(ModuleId, "chkAndMode", chkAndMode.Checked.ToString());
 
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion

    }
}
